package com.atguigu.gulimall.member.service.impl;

import org.springframework.stereotype.Service;
import java.util.Map;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.atguigu.common.utils.PageUtils;
import com.atguigu.common.utils.Query;

import com.atguigu.gulimall.member.dao.MemberDao;
import com.atguigu.gulimall.member.entity.MemberEntity;
import com.atguigu.gulimall.member.service.MemberService;
import org.springframework.util.StringUtils;


@Service("memberService")
public class MemberServiceImpl extends ServiceImpl<MemberDao, MemberEntity> implements MemberService {

    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        IPage<MemberEntity> page = this.page(
                new Query<MemberEntity>().getPage(params),
                new QueryWrapper<MemberEntity>()
        );

        return new PageUtils(page);
    }

    @Override
    public PageUtils queryPageByKey(Map<String, Object> params) {
        // 搜索关键字
        String key = (String) params.get("key");
        QueryWrapper<MemberEntity> queryWrapper = new QueryWrapper<>();
        if(!StringUtils.isEmpty(key) && !key.equals("0")){
            //根据id,或者用户名
            queryWrapper.eq("id", key).or().like("username", key);
        }

        IPage<MemberEntity> page = this.page(new Query<MemberEntity>().getPage(params), queryWrapper);

        return new PageUtils(page);

    }

}